package com.jbp.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jbp.dao.WechatConfigDao;
import com.jbp.model.AlipayConfig;
import com.jbp.model.WechatConfig;
import com.jbp.service.WechatConfigService;
import org.springframework.stereotype.Service;
import com.jbp.utils.PageUtils;
import com.jbp.utils.Query;

import java.util.List;
import java.util.Map;

/**
 * (WechatConfig)表服务实现类
 * @author cc
 * @since 2021-05-21 17:03:10
 */
@Service
public class WechatConfigServiceImpl extends ServiceImpl<WechatConfigDao, WechatConfig> implements WechatConfigService {
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<WechatConfig> queryWrapper = new QueryWrapper<>();
        if (params.get("id") != null){
            queryWrapper.like("id",params.get("id"));
        }
        IPage<WechatConfig> page = this.page(
                new Query<WechatConfig>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public WechatConfig getWechatAccount(Integer money) {
        WechatConfig wechatConfig = getOne(new QueryWrapper<WechatConfig>()
                .eq("del", 0)
                .eq("money", money));
        if (wechatConfig != null) {
            return wechatConfig;
        }
        List<WechatConfig> WechatConfigs = list(new QueryWrapper<WechatConfig>()
                .eq("del", 0)
                .orderByAsc("sort"));
        if (WechatConfigs != null && WechatConfigs.size() > 0){
            return WechatConfigs.get(0);
        } else {
            return null;
        }
    }
}